//
//  NavigationView.m
//  diaoyuren
//
//  Created by 钓鱼人 on 15/12/18.
//  Copyright © 2015年 game. All rights reserved.

#import "NavigationView.h"

#import "CityModel.h"
#import "Masonry.h"
@interface NavigationView()
@end

@implementation NavigationView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame ]) {
     
         self.cityBnt.titleLabel.font =font(14);

        [self.seachBnt setTitle:@"请输入关键词" forState:UIControlStateNormal];
        self.backgroundColor = mainColor;
        
        StatusWhite;
    }
        return self;
}

-(void)setWeathMode:(WeathForecastModel *)weathMode{
    _weathMode =weathMode;
    
    self.weatherBnt.enabled = YES;
    
    [self.weatherBnt setTitle:_weathMode.weather forState:UIControlStateNormal];

    [self.weatherBnt setImage:[UIImage imageNamed:_weathMode.weather_icon] forState:UIControlStateNormal];

    [self drawRect:self.frame ];
}


-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    
        [_seachBnt mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.right.equalTo(self.weatherBnt.mas_left).offset(-15);
        }];
}

-(UIButton *)cityBnt{
    if (!_cityBnt) {
 
        _cityBnt = [CityButton buttonWithType:UIButtonTypeCustom];
        
          NSUserDefaults *Myud = [NSUserDefaults standardUserDefaults];
        
        if (![Myud valueForKey:@"localName"]) {
            
            [Manager CityLocalAndPinYFromSQlWhithCityName:@"广州"AndIsNotificayion:NO];
        }
        
        
        NSString * cityName = [Myud valueForKey:@"localName"];
        
        if ([cityName isEqualToString:@"巴音郭楞"]) {
            cityName  = @"巴音郭...";
        }
        
         _cityBnt.text.text = cityName;
 
        [self addSubview:_cityBnt];
        
        [_cityBnt mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10);
            make.bottom.equalTo(@-7);

        }];
    }

        return _cityBnt;
}

-(UIButton *)weatherBnt{
    if (!_weatherBnt) {
        
        _weatherBnt = [UIButton buttonWithType:UIButtonTypeCustom];
        _weatherBnt.adjustsImageWhenHighlighted = NO;
        _weatherBnt.adjustsImageWhenDisabled = NO;
        _weatherBnt.titleLabel.font = font(SCREEN_WIDTH*0.048);
        _weatherBnt.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 5);
        
        [self addSubview:_weatherBnt];
        [_weatherBnt mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@-10);
            make.bottom.equalTo(@-10);
        }];
        
        _weatherBnt.enabled = NO;

    }

        return _weatherBnt;
}

-(UIButton *)seachBnt{
    if (!_seachBnt) {
        _seachBnt = [UIButton buttonWithType:UIButtonTypeCustom];
        _seachBnt.adjustsImageWhenDisabled = NO;
        _seachBnt.adjustsImageWhenHighlighted = NO;
        [_seachBnt setImage:[UIImage imageNamed:@"sousuo"] forState:UIControlStateNormal];
        _seachBnt.backgroundColor = RGBA(0, 0, 0, 0.15);
        _seachBnt.titleLabel.font = font(SCREEN_WIDTH*0.04);
        _seachBnt.titleLabel.alpha = 0.3;
        _seachBnt.imageEdgeInsets= UIEdgeInsetsMake(0, 5, 0, 0);
        _seachBnt.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        
        _seachBnt.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        radius(_seachBnt, 15);
        
        [self addSubview:_seachBnt];
        [_seachBnt mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(@-7);
            make.left.equalTo(_cityBnt.mas_right).offset(4);
            make.height.equalTo(@30);
//            make.width.equalTo(@(SCREEN_WIDTH*0.57));
        
        }];
    }
        return _seachBnt;
}
@end
